const app = getApp();
Page({
  data: {
    TabCur: 0,
    scrollLeft: 0,
    list: null,
    type:null,
    name:""
  },
  onLoad(option) {
    var that = this;
    that.setData({
      type: option.type
    }); 
    if (option.type==0){
      that.setData({
        name: "预约"
      });
      
    }else{
      that.setData({
        name: "收藏"
      });
    }
  },
  onShow() {
    this.init()
  },
  goInfo(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
    url: '/pages/activity/info/info?id=' + id
    })
  },
  init() {
    var that = this;
    var userId = app.globalData.userId;
    wx.request({
      url: app.globalData.local_url + 'api/myAppointmentList',
      data: {
        userId: userId,
        type: that.data.type
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.code == 200) {
          that.setData({
            list: res.data.data
          });

        } else {

        }
      }
    })
  },
  delete(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.request({
      url: app.globalData.local_url + 'api/deleteAppointment',
      data: {
        id: id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if (res.data.code == 200) {
          wx.showToast({
            title: '取消预约成功',
            icon: 'success',
            duration: 2000 //持续的时间
          });
          that.init()

        } else {

        }
      }
    })
  }
})